package com.situation.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situation.mapper.BizHealthMapper;
import com.situation.pojo.DO.BizHealth;
import com.situation.pojo.VO.HealthVO;
import com.situation.service.BizHealthService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class BizHealthServiceImpl implements BizHealthService {
    @Autowired
    private BizHealthMapper bizHealthMapper;


    @Override
    public PageInfo<HealthVO> selectById(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        String username=(String)SecurityUtils.getSubject().getPrincipal();
        List<HealthVO> bizHealths = bizHealthMapper.selectByUsername(username);
        return new PageInfo<>(bizHealths);

    }

    @Override
    public int add(BizHealth bizHealth) {
        return bizHealthMapper.add(bizHealth);
    }

    @Override
    public boolean isReport(BizHealth bizHealth) {
        List<HealthVO> bizHealths = bizHealthMapper.selectById(bizHealth.getUserId());
        for (HealthVO health : bizHealths) {
            LocalDateTime a= LocalDate.now().atTime(0,0,0);
            LocalDateTime b= LocalDate.now().atTime(23,59,59);
            LocalDateTime c=health.getCreateTime();
            if (c.isBefore(b)&&c.isAfter(a)){
                return true;
            }
        }
        return false;
    }
}
